package com.hontlong.aixue.validator;

import org.springframework.validation.Errors;
import org.springframework.validation.ValidationUtils;
import org.springframework.validation.Validator;

import com.hontlong.aixue.bean.User;

public class UserValidator implements Validator {
	public boolean supports(Class<?> arg0) {
		return User.class.isAssignableFrom(arg0);

	}

	public void validate(Object target, Errors errors) {
		ValidationUtils.rejectIfEmptyOrWhitespace(errors, "name", "name.empty");
		User user = (User) target;
		if (user.getUsername().length() > 20 || user.getUsername().length() < 4) {		
			errors.rejectValue("name", "name.error");
		}
	}
}
